import http from "../../../utils/https";

// mine/pages/myContract/myContract.js
Page({
  data: {
    contractList: []
  },

  onLoad: function (options) {
    this.loadContractList();
  },

  onShow: function () {
    // 页面显示时刷新数据
    this.loadContractList();
  },

  // 加载合同列表
  loadContractList() {
    http.get('contract/contract/byUpdate')
    .then(resp=>{
      if(resp.code==200){
        this.setData({
          contractList:resp.rows
        })
      }
    })
    .catch(err=>{
      console.log("请求错误",err);
    })
  },



  // 查看合同详情
  viewContractDetail: function (e) {
    const contract = e.currentTarget.dataset.contract;
    if (!contract) return;

    // 跳转到合同详情页面
    wx.navigateTo({
      url: `/mine/pages/myContractDetail/myContractDetail?contractId=${contract.id}`,
      fail: (err) => {
        console.error('跳转失败:', err);
        wx.showToast({
          title: '页面跳转失败',
          icon: 'none'
        });
      }
    });
  },



  // 下拉刷新
  onPullDownRefresh: function () {
    this.loadContractList();
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 1000);
  }
});